-- -------------------------------------------------------------------------- --
-- AssistMonitor by Taniane                                                   --
-- -------------------------------------------------------------------------- --
--                                                                            --
-- In battlegrounds and raids, leaders call out a target, and group members   --
-- are expected to assist. This isn’t always the case.                        --
-- This addon will track the baddies that aren’t doing what they are told.    --
--                                                                            --
-- Targit, this is for you.                                                   --                                                                           --
-- -------------------------------------------------------------------------- --

-- ---------------------------------------------------------------------------------------------------------------------

local am_version = "v1.0"

-- Key Bindings --
BINDING_HEADER_ASSISTMONHEADER = "AssistMonitor"
BINDING_NAME_ASSISTMONBIND = "Announce target to Raid"
BINDING_NAME_ASSISTMONBIND2 = "Show baddies"

-- Slash Commands --

SLASH_ASSISTMONITOR1 = "/am"
SLASH_ASSISTMONITOR2 = "/assistmon"
SLASH_ASSISTMONITOR3 = "/assistmonitor"


function cmd_help()
	print('AssistMonitor '..am_version..' by Taniane')
	print('Commands:')
	print('  target      Send raid warning with current target name')
	print('  baddies     Show list of baddies')
end

function cmd_baddies()
	local baddies = {}
	
    -- first, get our target. this is assuming we are the leader. --
	local mtarget = GetUnitName('target', false)
	
	-- next, step through each raid member --
	for num = 1, GetNumGroupMembers() do
		local unitID = 'raid'..num -- unit id that we're checking, such as raid1 --
		local unitName = GetUnitName(unitID, false) -- name of unit that we're checking ---
		local ttarget = GetUnitName(unitID..'target', false) -- get the target name of raid member --

		if ttarget ~= mtarget then
			table.insert(baddies, unitName) -- push the data to our baddies table --
		end
	end
	
	-- print baddies to the default chat frame --
	local cmsg = "AssistMonitor Baddies: "..table.concat(baddies, ", ")
	print(cmsg)
end

function cmd_target()
	local mtarget = GetUnitName('target', false)
	
	SendChatMessage(mtarget,'RAID_WARNING',nil,'')
end

local function handler(msg, editbox)
	local command, rest = msg:match("^(%S*)%s*(.-)$");
	-- TODO: print options --

	if command == 'target' then
		cmd_target()
	elseif command == 'baddies' then
		cmd_baddies()
	elseif command == 'help' then
		cmd_help()
	else
		print('AssistMonitor: unknown command '..command)
		cmd_help()
	end
end

SlashCmdList["ASSISTMONITOR"] = handler
-- ---------------------------------------------------------------------------------------------------------------------
